package nextel.usuario.bean;

import pe.com.nextel.rms.DataInputStreamX;
import pe.com.nextel.rms.DataOutputStreamX;
import pe.com.nextel.rms.PersistenteX;
import java.io.IOException;
import nextel.util.mvc.listenerLista;
import org.kxml2.io.KXmlParser;
import org.kxml2.io.KXmlSerializer;
import pe.com.nextel.util.ArrayList;
import pe.com.nextel.util.Iterator;
import pe.com.nextel.util.List;
import pe.com.nextel.util.StringUtils;



/**
 *
 * @author eespinoza
 */
public class GeneralBean extends PersistenteX implements listenerLista {
    
    public static final String GENERAL_ENTREGA = "1";
    public static final String GENERAL_MOTIVO = "2";
    public static final String GENERAL_META = "3";
    
   // public static final String ATRIBUTO_META_VITA = "4";
    //public static final String ATRIBUTO_META_ACTIVIDAD = "6";
    
    
    private String grupo;
    private String codigo;
    private String descripcion;
    private String valor;
    
    public String getCodigo() {
        return codigo;
    }
    
    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }
    
    public String getDescripcion() {
        return descripcion;
    }
    
    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }
    
    public void persistir(DataOutputStreamX dataOutput, List list) throws IOException {
        dataOutput.writeInt(list.size());
        
        for (Iterator it = list.iterator(); it.hasNext();) {
            GeneralBean bean = (GeneralBean) it.next();
            dataOutput.writeString(StringUtils.stringNullToBlank(bean.getGrupo()));
            dataOutput.writeString(StringUtils.stringNullToBlank(bean.getCodigo()));
            dataOutput.writeString(StringUtils.stringNullToBlank(bean.getDescripcion()));
            dataOutput.writeString(StringUtils.stringNullToBlank(bean.getValor()));
        }
    }
    
    public List recuperar(DataInputStreamX dataInput) throws IOException {
        List lista = new ArrayList();
        GeneralBean bean = null;
        
        int cant = dataInput.readInt();
        for (int i = 0; i < cant; i++) {
            bean = new GeneralBean();
            bean.setGrupo(dataInput.readString());
            bean.setCodigo(dataInput.readString());
            bean.setDescripcion(dataInput.readString());
            bean.setValor(dataInput.readString());
            lista.add(bean);
        }
        
        return lista;
    }
    
    public void persistirItem(DataOutputStreamX dataOutput) throws IOException {
        
        
        dataOutput.writeString(StringUtils.stringNullToBlank(getGrupo()));
        dataOutput.writeString(StringUtils.stringNullToBlank(getCodigo()));
        dataOutput.writeString(StringUtils.stringNullToBlank(getDescripcion()));
        dataOutput.writeString(StringUtils.stringNullToBlank(getValor()));
        
    }
    
    public void recuperarItem(DataInputStreamX dataInput) throws IOException {
        
        setGrupo(dataInput.readString());
        setCodigo(dataInput.readString());
        setDescripcion(dataInput.readString());
        setValor(dataInput.readString());
        
    }
    
    
    public String getGrupo() {
        return grupo;
    }
    
    public void setGrupo(String grupo) {
        this.grupo = grupo;
    }
    
    public void writeXMLObject(KXmlSerializer writer) throws IOException {
    }
    
    public void readXMLObject(KXmlParser parser) throws IOException {
        
        setGrupo(parser.getAttributeValue(null, "g").trim());
        setCodigo(parser.getAttributeValue(null, "c").trim());
        setDescripcion(parser.getAttributeValue(null, "d").trim());
        setValor(parser.getAttributeValue(null, "v").trim());
    }
    
    public String getValor() {
        return valor;
    }
    
    public void setValor(String valor) {
        this.valor = valor;
    }
    
    public void clear(){
        
    }
    
    public String getCampoMostrar(){
        return descripcion;
    }
    
}
